﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.util.SuperPage" %>
<%@ page import="com.mtbu.bean.SysLog" %>
<%@ page import="my.myorm.tool.jdbc.SQLExecutor" %>
<%@ page import="my.myorm.tool.jdbc.ResultList" %>
<%@ page import="my.myorm.tool.jdbc.Pages" %>
<%@ page import="my.myorm.tool.jdbc.SQLManager" %>
<%@ page import="com.util.SuperString" %>
<%@ page import="com.mtbu.comm.Util" %>
<%@ page import="com.util.SuperDate" %>
<%@ page import="java.util.Calendar" %>
<%@include file="sys_commcheck.jsp"%>
<%
    String curFile = SuperPage.getCurURLFile(request);
    String curName = "系统日志查看";

    String s_date=SuperString.notNullTrim(request.getParameter("s_date"));
    String key=SuperString.notNullTrim(request.getParameter("key"));
    String s_username=SuperString.notNullTrim(request.getParameter("s_username"));
    String s_operate=SuperString.notNullTrim(request.getParameter("s_operate"));
    int s_pagesize=SuperString.getInt(request.getParameter("s_pagesize"));
    String dropparam="s_date,s_username,s_operate,s_pagesize,key";
    if(request.getMethod().equalsIgnoreCase("post")){
        StringBuffer sbparam=new StringBuffer();
        sbparam.append("&issearch=1");
        if(!"".equals(s_date)) sbparam.append("&s_date=").append(Util.encodeUrl(s_date));
        if(!"".equals(s_username)) sbparam.append("&s_username=").append(Util.encodeUrl(s_username));
        if(!"".equals(s_operate)) sbparam.append("&s_operate=").append(Util.encodeUrl(s_operate));
        if(!"".equals(key)) sbparam.append("&key=").append(Util.encodeUrl(key));
        if(s_pagesize>0) sbparam.append("&s_pagesize=").append(s_pagesize);
        String strparam=sbparam.toString();
        if(strparam.startsWith("&")) strparam="?"+strparam.substring(1);
        strparam+="".equals(strparam)? SuperPage.getQueryQ(request,dropparam): SuperPage.getQueryAnd(request,dropparam);
        response.sendRedirect(curFile+strparam);
        return;
    }
    key=SuperString.replace(key,"'","\\'");
    s_username=SuperString.replace(s_username,"'","\\'");
    s_operate=SuperString.replace(s_operate,"'","\\'");

    SuperDate sddate=SuperString.isDateString(s_date)?new SuperDate(s_date,true):null;
    if(sddate==null&&!Constant_isSuperAdmin){
        sddate=new SuperDate(new SuperDate().getDateString(),true);
    }


    //组合条件
    StringBuffer strw = new StringBuffer();
    if(sddate!=null) strw.append("and createtime>='").append(sddate.getDateTimeString())
            .append("' and createtime<'").append(sddate.getAddedDate(Calendar.DAY_OF_YEAR,1).getDateTimeString()).append("' ");
    if(!"".equals(s_username)) strw.append("and username='").append(s_username).append("' ");
    if(!"".equals(s_operate)) strw.append("and operate='").append(s_operate).append("' ");
    if(!"".equals(key)) strw.append("and content like '").append(key).append("%' ");
    if(!Constant_isSuperAdmin) strw.append("and username<>'admin' ");

    String strwhere = Util.getWhereSQL(strw);

    String order = SuperString.notNullTrim(request.getParameter("order"));
    String orderby = order.length() == 0 ? " order by id desc" :
            " order by " + order;    

    SQLExecutor dbconn = SQLManager.getSQLExecutor();
    String sql="select * from sys_log "+ strwhere + orderby;
    int pagesize=Util.getPropertiesInt("CONST_PAGESIZE",30);
    if(s_pagesize>0) pagesize=s_pagesize;
    Pages pages = new Pages(pagesize, "id", request);
    ResultList rs =dbconn.query(sql,false,pages);

%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><%=curName%></title>
<link href="css/common.css" rel="stylesheet" type="text/css">
<script language="javascript" src="js/comm.js"></script>
<script language="javascript" src="js/tablecell.js"></script>    
</head>

<body>
<script type="text/javascript" src="js/calendar.js"></script>

<div class="title_text"><%=curName%></div>

<fieldset class="order_fieldset">
    <legend>输入查询条件</legend>
    <table width="100%"  border="0" cellspacing="1" cellpadding="2" style="margin:5px 0;">
      <form name="form_s" action="<%=curFile%><%=SuperPage.getQueryQ(request,dropparam)%>" method="post" class="formline">
        <tr>
          <td width="91%">日期
            <input name="s_date" type="text" class="input_date" id="s_date" value="<%=sddate!=null?sddate.getDateString():""%>" title="日期" onFocus="calendar(EventUtil.getEvent().target)" size="12" maxlength="10" readonly="true" AUTOCOMPLETE="off">
            用户
            <input name="s_username" type="text" id="s_username" title="用户" value="<%=s_username%>" size="12" maxlength="30">
            操作
            <input name="s_operate" type="text" id="s_operate" title="操作" value="<%=s_operate%>" maxlength="30">
            内容关键字
            <input name="key" type="text" id="key" title="关键字" value="<%=key%>" maxlength="50">
            每页显示
            <input name="s_pagesize" type="text" id="s_pagesize" title="每页显示" value="<%=s_pagesize>0?s_pagesize:""%>" size="2" maxlength="6">
            <input name="Submit2" type="submit" class="BUTTON3" value=" 搜索 "></td>
          <td width="9%" align="right">&nbsp;</td>
        </tr>
      </form>
    </table>
</fieldset>
<div style="height:2px;"><span/></div>

<div class="page_nav00"><%=SuperPage.generatePageNavSingle(rs.getAllCount(), request, null, pages.getPageSize(),"个")%></div>

<table width="100%" border="0" cellpadding="3" cellspacing="1" class="table_bord">
  <tr class="table_bord_ttl">
    <td>用户</td>
    <td>操作</td>
    <td>内容</td>
    <td>IP</td>
    <td onClick="title_click('<%=Util.getOrderUrl("id",order,request)%>')">时间<%=Util.getOrderByImgHTML("id",order)%></td>
  </tr>
<%
    for(int i = 0; i < rs.size(); i++) {
        SysLog log= rs.get(i).get(SysLog.class);
        String trclass = i % 2 == 0 ? "tr_class1" : "tr_class2";
%>
  <tr class="<%=trclass%>" onMouseMove="cell_over(this);" onMouseOut="cell_out(this)" onClick="cell_click(this);">
    <td><%=log.getUserName()%></td>
    <td><%=log.getOperate()%></td>
    <td><%=log.getContent()%></td>
    <td class="font12"><%=log.getIP()%></td>
    <td class="font12"><%=log.getCreateTime_ToDateTimeString()%></td>
  </tr>
<%
    }
    if(rs.size()==0){
%>
  <tr bgcolor="#FFFFFF">
    <td height="50" colspan="5" align="center">没有数据</td>
  </tr>
  <%
    }
%>
</table>
<div class="page_nav01"><%=SuperPage.generatePageNavSingle(rs.getAllCount(), request, null, pages.getPageSize(),"个")%></div>
<div style="height:30px;"/>
</body>
</html>